<template>
  <!--  近2周记录-->
  <div class="container-big">
    <div class="content-big">
      <div class="content-left">
        <div class="content-item">
          <div class="content-top">
            <div class="title">社群行为</div>
            <div class="mgt"><span>管理</span>
              <el-dropdown style="margin-right: 10px">
                <i class="el-icon-more"></i>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>重命令</el-dropdown-item>
                  <el-dropdown-item>复制</el-dropdown-item>
                  <el-dropdown-item>删除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </div>
          <div class="label-list">
            <span>未入常规群</span>,
            <span>未入常规群</span>
          </div>
          <div class="content-bottom">
            <div class="content-id">id:1106164</div>
            <div class="content-type">类型：默认</div>
          </div>
        </div>
        <div class="content-item active">
          <div class="content-top">
            <div class="title">私聊活跃程度</div>
            <div class="mgt">
              <el-switch
                v-model="value"
                active-color="#13ce66">
              </el-switch>
            </div>
          </div>
          <div class="label-list">
            <div class="red">未配置规则</div>
          </div>
          <div class="content-bottom">
            <div class="content-id">id:1106164</div>
            <div class="content-type">类型：默认</div>
          </div>
        </div>

        <div class="moreInfo">
          <el-tooltip class="item" effect="dark" content="" placement="top-start">
            <div slot="content">
              行为标签目前只提供社群行为和私聊活跃度相关的场景，后续会不断增强，支持更多的行为场景，欢迎大家结合实际业务场景联系我们一起探讨实现。
              <br/>当前系统能够识别获取的包含但不限于下列行为：
              <br/>1、 客户发言：包含私聊、群聊；
              <br/>2、 发言内容、频次、间隔等分析；
              <br/>3、 客户进群退群；
              <br/>4、 客户进群邀请关系；
              <br/>5、 客户添加、删除、拉黑好友。
            </div>
            <el-button>更多行为</el-button>
          </el-tooltip>
        </div>
      </div>
      <div class="content-right">
        <ul class="table-list">
          <li :class="active==index?`active`:``" v-for="(item,index) in tablist" @click="getActive(index)">{{ item.label }}</li>
        </ul>
        <div class="right-big">
          <div class="ruleSet" v-if="active==0">
            <div class="title">标签规则：</div>
            <div class="ruleSet-table">
              <el-button type="primary" plain size="small" @click="addRules('add')">添加规则</el-button>
              <el-table
                :data="tableDataList"
                :max-height="tableHeight"
                ref="companylabelList"
                @selection-change="handleSelectionChange"
              >
                <el-table-column
                  :label="item.label"
                  :align="item.align?item.align:`center`"
                  v-for="(item, index) in tableColumns"
                  :key="index"
                  :prop="item.key"
                  :min-width="item.minWidth ? item.minWidth : ``"
                  :fixed="item.fixed ? item.fixed : false"
                  :show-overflow-tooltip="true"
                >
                  <!--用于表格自定义-->
                  <template slot-scope="scope">
                    <div v-if="item.key=='name'">
                      已加入群聊，打上
                      <el-tag type="info" size="small">已入常规群</el-tag>
                      移除
                      <el-tag type="info" size="small">未入常规群</el-tag>
                    </div>
                    <div class="label-list" v-else-if="item.key=='label'">
                      5企微号的，<span>0</span>个群 <span>0</span>个群标签
                    </div>

                    <div v-else style="text-align: center">{{ scope.row[item.key] }}</div>
                  </template>
                </el-table-column>
                <el-table-column
                  fixed="right"
                  label="操作"
                  align="center"
                  width="200">
                  <template slot-scope="scope">
                    <el-button type="text" size="small">编辑</el-button>
                    <el-button type="text" size="small">删除</el-button>

                  </template>
                </el-table-column>
              </el-table>
              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
            </div>
          </div>
          <!--          标签变更记录-->
          <template v-if="active==1">
            <div class="recordTalbel">
              <el-table
                :data="recordDataList"
                ref="companylabelList"
                @selection-change="handleSelectionChange"
              >
                <el-table-column
                  :label="item.label"
                  align="left"
                  v-for="(item, index) in recordTableColumns"
                  :key="index"
                  :prop="item.key"
                  :min-width="item.minWidth ? item.minWidth : ``"
                  :fixed="item.fixed ? item.fixed : false"
                  :show-overflow-tooltip="true"
                >
                  <!--用于表格自定义-->
                  <template slot-scope="scope">
                    <div v-if="item.key=='name'">
                      <div class="userInfo">
                        <img src="@/assets/images/profile.jpg"/>
                        <div class="name">小城红</div>
                        <div class="label">@志新</div>
                      </div>
                    </div>
                    <div class="label-list" v-else-if="item.key=='label'">
                      <label>自动打上：</label>
                      <span>未入VIP群</span>
                      <span>持续7天未发言</span>
                      <span>1000</span>
                    </div>
                    <div v-else-if="item.key=='code'">
                      <div class="userInfo">
                        <img src="@/assets/images/profile.jpg"/>
                        <div class="name">小城红</div>
                        <div class="label">@志新</div>
                      </div>
                    </div>
                    <div v-else>{{ scope.row[item.key] }}</div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </template>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
import {listUser, delUser,} from "@/api/system/user";

export default {
  name: "activelabel",
  components: {
    // 'addOrEditUserOperations': () => import('./addOrEditUserOperations.vue'),//导出弹窗\
    // 'editName': () => import('./editName.vue'),//导出弹窗
    // 'editSendSettings': () => import('./editSendSettings.vue'),//导出弹窗
  },
  data() {
    return {
      tablist: [
        {
          value: 1,
          label: '规则设置',
        },
        {
          value: 2,
          label: '标签变更记录',
        },
      ],
      active: 0,
      visible: false,

      dialogType: 'add',
      showExportPage: false,//导出
      tableHeight: 600,
      tableDataList: [],
      tableColumns: [
        {key: 'name', label: `标签规则`, visible: true, minWidth: 150, fixed: true, align: 'left'},
        {key: 'label', label: `目标客户群`, visible: true, minWidth: 150, fixed: false},
      ],
      recordDataList: [],
      recordHeight: 600,
      recordTableColumns: [
        {key: 'name', label: `客户`, visible: true, minWidth: 150, fixed: true},
        {key: 'label', label: `标签`, visible: true, minWidth: 150, fixed: false},
        {key: 'code', label: `所属企微号`, visible: true, minWidth: 150, fixed: false},
        {key: 'time', label: `变更时间`, visible: true, minWidth: 150, fixed: false},
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        userName2: null,
        pageSize: 10,
        id: null,//用户id
        userName1: null,

      },
      total: 8, // 表格的总条数
    };
  },
  created() {
    // this.getList();
    this.tableDataList = [];
    for (let i = 0; i < 3; i++) {
      let obj = {
        name: '小红',
        label1: '18207418337',
        label2: '18207418337',
        label3: '18207418337',
        label4: '18207418337',
      }
      this.tableDataList.push(obj);
    }
    this.recordDataList = [];
    for (let i = 0; i < 10; i++) {
      let obj = {
        name: '小红',
        label: '18207418337',
        code: '111',
        time: '2012-08-12'
      }
      this.recordDataList.push(obj);
    }
  },
  methods: {
    getActive(index) {
      this.active = index;
    },
    handerEditName() {
      console.log('111111111111111')
      this.showEditName = true;
    },
    addRules(type) {
      this.$router.push({
          path: '/IntelligentOperationMgt/inoperationMgt/components/addOrEditRules',
          query: {
            type: type,
          }
        }
      )
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableDataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(val) {
      this.multipleSelection = [];
      if (val && val.length > 0) {
        val.forEach((item) => {
          this.multipleSelection.push(item.id);
        })
        console.log('multipleSelection', this.multipleSelection);
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      //删除
      // const userIds = row.userId || this.ids;
      // this.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项？').then(function () {
      //   return delUser(userIds);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => {
      // });
      this.$msgBox.showMsgBox({
        title: "是否确认删除？",
        content: "该企微号正在执行服务，删除将会使该号从操作中释放，导致部分功能无法正常使用，请谨慎选择。*如该号已加入在线聊天，成功删除后，聊天记录会被一并删除，重新登录后无法恢复。",
      })
        .then(async (val) => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleNumberDelete() {
      this.$modal.confirm('确认清空本页黑名单？').then(function () {
        return delUser(userIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });

    },

  }
};
</script>
<style lang="scss" scoped>
.head-big {
  display: flex;
  justify-content: space-between;
  padding: 20px;
  padding-bottom: 0px;
}

.container-big {
  display: flex;
  height: calc(100vh - 100px);
  margin: 12px;
  flex-direction: column;
}

.content-left {
  width: 400px;
}

.formGroup {
  width: 100%;
  padding: 10px 20px;
  margin-bottom: 10px;
  background: #fff;

  .el-form {
    background: #fff;
    border-radius: 8px;
    margin-top: -1px;
    display: flex;

    .el-button {
      margin-right: 10px;
    }

    .el-form-item {
      margin-bottom: 0px;

      ::v-deep .el-form-item__content {
        display: flex;

        .el-input {
          width: 150px;
        }
      }



    }
  }
}

.right-big {
  border-radius: 4px;
  padding-left: 11px;
  height: calc(100% - 50px);
  overflow-y: auto;
  position: relative;

  > span {
    color: #777;
    width: 89px;
    display: inline-block;
    white-space: nowrap;
  }

  .el-select {
    width: 138px;

    ::v-deep .el-input__inner {
      border: none;
    }
  }

  .el-input {
    width: 138px;

    ::v-deep .el-input__inner {
      border: none;
    }
  }

  ::v-deep .el-date-editor {
    border: none;
  }
}
.header-top {
  height: 46px;
  background: #fff;
  border-bottom: 1px solid #e9e9e9;
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 20px;

  .head-title {
    font-size: 14px;
    line-height: 22px;
    margin-right: 10px;

    .example-text {
      color: #2f54eb;
      cursor: pointer;
      margin-left: 8px;;
      font-weight: 400;

      &:hover + .example-modal {
        display: block;
      }
    }

    .example-modal {
      position: fixed;
      left: 0;
      margin-top: 10px;
      display: none;
      border-radius: 4px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
      background: #FFFFFF;

      .example-cover {
        height: 600px;
      }
    }
  }

  .divider {
    margin: 0 20px;
    width: 1px;
    height: 16px;
  }
}


.head-right {
  .el-dropdown {
    margin-right: 10px;
  }

  .el-button {
    i {
      margin-right: 5px;
    }
  }
}

.other-option {
  height: 30px;
  display: flex;
  align-items: center;
  color: #2d8cf0;
  font-size: 14px;
  margin-left: 15px;
  border-top: 1px solid #eee;
}

.status {
  &.green {
    color: #1ab394;
  }
}

.content-big {
  height: calc(100vh - 150px);
  .content-left {
    width: 414px;
    display: flex;
    flex-direction: column;

    .content-item {
      background: #fff;
      border-radius: 4px;
      border: 1px solid #e9e9e9;
      cursor: pointer;
      margin: 0px 10px;
      margin-bottom: 10px;

      &.active {
        border: 1px solid #3070ff;
        background: #ebf2ff;
        box-shadow: 0 0 4px 0 rgba(0, 0, 0, .2);
      }

      .content-top {
        display: flex;
        justify-content: space-between;
        olor: rgba(0, 0, 0, .85);
        display: flex;
        align-items: center;
        grid-gap: 8px;
        gap: 8px;
        padding: 12px;
        padding-bottom: 0;

        .title {
          font-size: 14px;
        }

        .mgt {
          font-size: 12px;
          border: 1px solid #eee;
          height: 24px;
          display: flex;
          align-items: center;
          padding: 0px 5px;
          border-radius: 5px;


          span {
            margin-right: 5px;
            border-right: 1px solid #eee;
          }
        }
      }

      .label-list {
        color: rgba(0, 0, 0, .45);
        font-size: 12px;
        margin-bottom: 12px;
        padding: 0px 12px;
        padding-top: 5px;

        .red {
          color: red;
        }
      }

      .content-bottom {
        display: flex;
        justify-content: space-between;
        font-size: 12px;
        color: rgba(0, 0, 0, .45);
        padding: 6px 12px;
        border-top: 1px solid #e9e9e9;
      }
    }
  }

  .formGroup {
    display: flex;
  }
}

.content-big {
  display: flex;

  .content-right {
    flex: 1;
    background: #fff;
  }
}

.moreInfo {
  color: #2d8cf0;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
}

.table-list {
  font-size: 14px;
  margin-right: 10px;
  display: flex;
  align-items: center;
  background: #fff;
  padding: 0px 20px;
  border-bottom: 1px solid #eee;

  li {
    cursor: pointer;
    font-weight: 400;
    list-style: none;
    margin: 0px 10px;
    position: relative;
    display: flex;
    height: 44px;
    align-items: center;

    &.active {
      color: #3070ff;

      &:after {
        content: '';
        position: absolute;
        height: 2px;
        background: #3070ff;
        width: 100%;
        bottom: 0px;
        left: 0px;
      }
    }
  }

  .example-modal {
    position: fixed;
    left: 0;
    margin-top: 10px;
    display: none;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    background: #FFFFFF;

    .example-cover {
      height: 600px;
    }
  }
}

.ruleSet {
  display: flex;
  margin-top: 20px;
  padding: 0 20px 20px;

  .title {
    width: 100px;
    font-size: 14px;
  }

  .ruleSet-table {
    flex: 1;

    .el-table {
      margin-top: 10px;
    }
  }
}

.userInfo {
  border-radius: 4px;
  margin: 8px 0;
  cursor: pointer;
  position: relative;
  padding-left: 50px;
  font-size: 14px;
  list-style: none;
  text-align: left;

  img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    left: 0px;
    top: 0px;
    position: absolute;
  }

  .label {
    margin-top: 2px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #f90;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.label-list {
  label {
    font-size: 14px;
    line-height: 1.5715;
    word-wrap: break-word;
    font-weight: 400;
  }

  span {
    margin: 4px 4px 4px 0;
    font-size: 12px;
    height: 25px;
    line-height: 25px;
    white-space: nowrap;
    background: #f0f0f0;
    border: 1px solid #e9e9e9;
    border-radius: 4px;
    padding: 0px 7px;
    display: inline-block;

  }
}

.recordTalbel {
  margin: 20px;
}
</style>
